|
|
|
|
|
|
|
application, coding an FTP function allows users to get updated information for the application directly from the Internet. Another reason for using this function is to provide users with a way of getting upgrades for their application files without waiting for disks to be sent to them. |
|
|
|
|
|
|
|
|
The Execute method has four arguments: url, operation, data, and requestHeaders. FTP operations require only the operation and url arguments. For example, to get a file from a remote computer, you could use the following code: |
|
|
|
|
|
|
|
|
Inet1.Execute FTP://ftp.microsoft.com, GET disclaimer.txt
C:\Temp\Disclaimer.txt |
|
|
|
|
|
|
|
|
If you're used to using FTP to retrieve files from anonymous FTP servers, you'll be familiar with the commands used to navigate through server trees and to retrieve files to a local hard disk. For example, to change directories, you would use the command CD with the path of the directory you want to change to. For the most common operations, such as putting a file on a server and retrieving a file from a server, the File Transfer control uses the same or a similar command with the Execute method. For example, the following code uses the CD command as an argument of the Execute method to change directories: |
|
|
|
|
|
|
|
|
Inet1.Execute txtURL.Text, CD & txtRemotePath.Text |
|
|
|
|
|
|
|
|
Because an asynchronous connection is used when you're downloading data from a remote computer, the StateChanged event is used to determine the status of the operation. For example, using the Execute method with the GET operation causes the server to retrieve the requested file. When the process is completed, the State argument returns an icResponseCompleted value. At that point, you can use the GetChunk method to retrieve the data from the buffer, as follows: |
|
|
|
|
|
|
|
|
Private Sub Inet1_StateChanged(ByVal State As Integer)
Dim vtData As Variant
Select Case State
Case icResponseCompleted
Open txtOperation For Binary Access Write As intFileNum
vtData = Inet1.GetChunk(1024, icString)
Do While LenB(vtData) > 0
Put intFileNum, , vtData
vtData = Inet1.GetChunk(1024, icString)
Loop
Put intFileNum, , vtData
Close intFileNum
End Select
End Sub |
|
|
|
|
|